﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace awsomeSyntezator.PipeLine
{
    class Filter : Block
    {
    	public float cutOffFrequency;
		public double resonance;


		public double s, c, a, r;
		public double a0 , a1 , a2 , b1 , b2;

    	public double oldSample1, oldSample2;
		public double filtredSample1, filtredSample2;

        public Filter (float cutOff, double reson)
        {
            type = 3;
        	cutOffFrequency = cutOff;
        	resonance = reson;

			oldSample1 = 1.0;
			oldSample2 = 1.0;
			filtredSample1 = 1.0;
			filtredSample2 = 1.0;

			s = Math.Sin((2.0 * Math.PI * cutOffFrequency) / (double)Options.rate);
			c = Math.Cos((2.0 * Math.PI * cutOffFrequency) / (double)Options.rate);
			a = s / (2 * resonance);
			r = 1 / (1 + a);
        }
		public virtual void setCutOffFrequency(float cutOff)
		{
			cutOffFrequency = cutOff;
			s = Math.Sin((2.0 * Math.PI * cutOffFrequency) / (double)Options.rate);
			c = Math.Cos((2.0 * Math.PI * cutOffFrequency) / (double)Options.rate);
			a = s / (2 * resonance);
			r = 1 / (1 + a);
		}
		public void setParams(float cutOff, int res)
		{
			resonance = res;
		    setCutOffFrequency(cutOff);
		}
    }
}
